#ifndef _ANIMACION
#define _ANIMACION

#include "objReader.h"
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <dirent.h> 
#include <vector>
#include <algorithm>
#include "SampleUtils.h"

#ifdef USE_OPENGL_ES_1_1
#include <GLES/gl.h>
#include <GLES/glext.h>
#else
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#endif

using namespace std;


class animacion{

private:
	vector<obj3d*> objs;
	int ind;
public:
	animacion(const string dir){
		LOG("constructor animacion");
		DIR *pdir = NULL; 
		pdir = opendir (dir.c_str()); 
		struct dirent *pent = NULL;
		if (pdir == NULL)  { 
			LOG("\nERROR! pdir could not be initialised correctly");
			return; 
		} 

		while (pent = readdir (pdir)) {
			if (pent == NULL){ 
            LOG ("\nERROR! pent could not be initialised correctly");
            return; // exit the function
			}
			
			string name=pent->d_name;
			LOG("%s",name.c_str());
			if(name.size()<5)continue;
			string ext=name.substr(name.size()-4, name.size());
					
			if(ext==".obj"){
				LOG ("anim: %s\n", pent->d_name);	
				string path=dir+name;
				objs.push_back(loadOBJ(path));
			}
			
		}
		closedir (pdir);
	}


	obj3d* next(){
		ind++;
		ind=ind%objs.size();
		return objs[ind];

	}

	void draw(){
		next()->draw();
	}
	
	void setInd(int i){
		ind=i;
		ind=ind%objs.size();
	}

};


#endif
